package com.tanhua.mangement.controller;

import com.tanhua.mangement.service.ManageVideosService;
import com.tanhua.mangement.vo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/manage")
@Slf4j
public class ManageVideosController {

    @Autowired
    private ManageVideosService manageVideosService;

    /**
     * 视频记录翻页
     *
     * @param uid
     * @param page
     * @param pageSize
     * @param sortProp
     * @param sortOrder
     * @return
     */
    @GetMapping("videos")
    public ResponseEntity<PageResult> queryManageVideos(@RequestParam(value = "uid") Long uid,
                                                        @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                        @RequestParam(value = "sortProp") String sortProp,
                                                        @RequestParam(value = "sortOrder") String sortOrder) {

        //接收前端参数查询视频列表
        try {
            PageResult pageRequest = manageVideosService.queryManageVideos(uid, page, pageSize, sortProp, sortOrder);

            //判断返回的数据是否为空
            if (pageRequest != null) {

                //若不为空则返回数据
                return ResponseEntity.ok(pageRequest);
            }
        } catch (Exception e) {
            log.error("查询视频列表出错!", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}

